home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Apps / Apps.major.cgi.z / Apps.major.cgi
Encoding:
Text File  |  2002-06-12  |  7.3 KB  |  227 lines

  1. #!/usr/bin/perl5
  2.  
  3. # Apps.major.cgi
  4. # Silicon Graphics
  5.  
  6. require "/usr/OnRamp/lib/OnRamp.pm";
  7. require "/usr/OnRamp/lib/java.pm";
  8.  
  9. open(IN, "< ../admin/majordomo_data");
  10. while (<IN>) {
  11.     chomp;
  12.     ($key, $val) = split(/=/);
  13.     $data{$key} = $val;
  14. }
  15. close(IN);
  16.  
  17. $title       = "Majordomo Mailing Lists";
  18. $myname      = "Apps.major.cgi";
  19. $info_url    = $ENV{'SERVER_URL'} . "/apps/major-info.cgi";
  20. $archive_url = $ENV{'SERVER_URL'} . "/apps/major-archive.cgi";
  21. $archive_dir = "$document_root/apps/majordomo";
  22. $lists_dir   = "$data{'maj_home'}/lists";
  23. $aliases     = "/etc/aliases";
  24.  
  25. opendir(DIR, "$archive_dir");
  26. @archives = grep(!/^\.\.?$/, readdir(DIR));
  27. closedir(DIR);
  28. @archives = sort(@archives);
  29.  
  30. opendir(DIR, "$lists_dir");
  31. @lists = grep(/^.*\.config$/, readdir(DIR));
  32. closedir(DIR);
  33. foreach $list (@lists) { $list =~ s/\.config//g; }
  34. @lists = sort(@lists);
  35.  
  36. &get_fields;
  37.  
  38. $js = "
  39. $js_error_box
  40. which = \"none\";
  41. function runSubmit() {
  42.     form = document.Form;
  43.     if (which == \"sub\" || which == \"uns\") {
  44.         if (form.email.value == \"\") {
  45.             errorBox(form.email, \"Email address required.\");
  46.             return (false);
  47.         } 
  48.         if (form.s_list.value == \"\") {
  49.             errorBox(form.s_list, \"List name required.\");
  50.             return (false);
  51.         }
  52.     }
  53.     if (which == \"loc\") {
  54.         if (form.email.value == \"\") {
  55.             errorBox(form.email, \"Email address required.\");
  56.             return (false);
  57.         }
  58.     }
  59.     return (true);
  60. }
  61. function markSub() { which = \"sub\"; }
  62. function markUns() { which = \"uns\"; }
  63. function markLocate() { which = \"loc\"; }
  64. ";
  65.  
  66. if ($fld{'locate'}) {
  67.     $email = $fld{'email'};
  68.     foreach $list (@lists) {
  69.         $file = $lists_dir . "/" . $list;
  70.         open(IN, "< $file");
  71.         while(<IN>) {
  72.             chop $_;
  73.             push(@subsc, $list) if ($email eq $_);
  74.         }
  75.         close(IN);
  76.     }
  77.  
  78. } elsif ($fld{'subscribe'} || $fld{'unsub'}) {
  79.     $email = $fld{'email'};
  80.     $list = $fld{'s_list'};
  81.     if ($fld{'subscribe'}) { 
  82.         &send_message("subscribe", $list, $email);
  83.         $message .= "$email subscribed to $list.<br>\n"; 
  84.     } else { 
  85.         &send_message("unsubscribe", $list, $email); 
  86.         $message .= "$email removed from $list.<br>\n"; 
  87.     }
  88. }
  89.  
  90. &generic;
  91.  
  92. sub generic {
  93.     print "Content-type: text/html\n\n";
  94.     &js_title_block("Majordomo", $js);
  95.     print "<body bgcolor=#B8E5C0 background=/apps/major.bg.gif>\n";
  96.  
  97.     open(IN, "< $aliases");
  98.     while(<IN>) { $owner{$1} = $2 if ($_ =~ /^owner-(.*):\s+(.*)/); }
  99.     close(IN);
  100.  
  101.     print "<table width=100%><tr><th align=left><h2>$title</h2></th>\n",
  102.         "<th align=right><a href=\"/newsplash.shtml\">",
  103.         "<img height=55 width=57 border=0 src=/apps/home.gif></a>\n",
  104.         "  <a href=\"Apps.shtml\">",
  105.         "<img height=55 width=57 border=0 src=/apps/back.gif></a>",
  106.         "</tr></table><br><br>\n<form name=Form method=post action=$myname ",
  107.         "onSubmit=\"return runSubmit()\">\n";
  108.  
  109.     print "<font size=5><b><tt>Subscriptions:</tt></b></font><br>\n";
  110.     print "<p><i>$message</i>\n";
  111.  
  112.     print "<center><table width=80%>\n";
  113.     print "<tr align=left><th width=30%>Email address:<td width=20%>", 
  114.           &text("email", "", 15), "</td>\n";
  115.     print "<td width=20%><input type=\"submit\" onClick=\"markSub()\" ",
  116.           "name=\"subscribe\" value=\"  Subscribe  \"></td></tr>";
  117.     print "<tr><th align=left width=30%>Mailing list:<td width=20%>",
  118.           &text("s_list", "", 15), "</td>\n";
  119.     print "<td width=20%><input type=\"submit\" onClick=\"markUns()\" ",
  120.           "name=\"unsub\" value=\"Unsubscribe\"></td></tr>\n";
  121.     print "<tr><th align=left colspan=2 width=50%>Locate mailing lists ",
  122.           "currently subscribed to:\n";
  123.     print "<td width=20%><input type=\"submit\" onClick=\"markLocate()\" ",
  124.           "name=\"locate\" value=\"    Search     \"></td></tr>\n";
  125.  
  126.     if ($fld{'locate'}) {
  127.         if ($#subsc == -1) { 
  128.             print "<tr><td colspan=3><i>$email is not subscribed to any "
  129.                   . "mailing lists on this server.</i><br></td></tr>\n"; }
  130.         else { 
  131.             print "<tr><td colspan=3><i>$email is currently subscribed to: "
  132.                   . "</i><ul>\n";
  133.             foreach (@subsc) {
  134.                 $url = $info_url . "?$_:$owner{$_}";
  135.                 print "<li><a href=$url>$_</a>\n";
  136.             }
  137.             print "</ul></td></tr>\n";
  138.         }
  139.         print "<br>\n";            
  140.     }
  141.     print "</table></center>";
  142.     print "<hr><br>\n";
  143.  
  144.     print "<font size=5><b><tt>Mailing lists:</tt></b></font><br>\n";
  145.  
  146.     if ($#lists > -1) {
  147.  
  148.         $third = ($#lists + 1)/3;
  149.         if ($third =~ /([0-9]+)\./) { $third = $1; }
  150.         $rem = ($#lists + 1) % 3;
  151.         if ($rem == 0) { $a = $third; $b = $third; $c = $third; }
  152.         elsif ($rem == 1) { $a = $third+1; $b = $third; $c = $third; }
  153.         else { $a = $third+1; $b = $third+1; $c = $third; }
  154.     
  155.         print "<blockquote>\n";
  156.         print "<table width=80%><tr><td valign=top><ul>";
  157.         for ($i=0; $i<$a; $i++) { 
  158.             $url = $info_url . "?$lists[$i]:$owner{$lists[$i]}";
  159.             print "<li><a href=$url>$lists[$i]</a>\n";
  160.         }
  161.         print "</ul></td><td valign=top><ul>\n";
  162.         for ($i=$a; $i<$a+$b; $i++) { 
  163.             $url = $info_url . "?$lists[$i]:$owner{$lists[$i]}";
  164.             print "<li><a href=$url>$lists[$i]</a>\n";
  165.         }
  166.         print "</ul></td><td valign=top><ul>\n";
  167.         for ($i=$a+$b; $i<=$#archives; $i++) { 
  168.             $url = $info_url . "?$lists[$i]:$owner{$lists[$i]}";
  169.             print "<li><a href=$url>$lists[$i]</a>\n";
  170.         }
  171.         print "</ul></td></tr></table>\n";
  172.         print "</blockquote>\n";
  173.     
  174.         print "<hr><br>\n";
  175.     } else {
  176.         print "<center><table width=80%>\n";
  177.         print "<tr><td><i><p><br>\n"
  178.             . "There are currently no mailing lists."
  179.             . "</i></td></tr>\n";
  180.         print "</table></center>\n";
  181.     }
  182.  
  183.     if ($#archives > -1) {
  184.         print "<font size=5><b><tt>Message archives:</tt></b></font><br>\n";
  185.  
  186.         $third = ($#archives + 1)/3;
  187.         if ($third =~ /([0-9]+)\./) { $third = $1; }
  188.         $rem = ($#archives + 1) % 3;
  189.         if ($rem == 0) { $a = $third; $b = $third; $c = $third; }
  190.         elsif ($rem == 1) { $a = $third+1; $b = $third; $c = $third; }
  191.         else { $a = $third+1; $b = $third+1; $c = $third; }
  192.     
  193.         print "<blockquote>\n";
  194.         print "<table width=80%><tr><td valign=top><ul>";
  195.         for ($i=0; $i<$a; $i++) {
  196.             $url = $archive_url . "?$archives[$i]";
  197.             print "<li><a href=$url>$archives[$i]</a>\n";
  198.         }
  199.         print "</ul></td><td valign=top><ul>\n";
  200.         for ($i=$a; $i<$a+$b; $i++) {
  201.             $url = $archive_url . "?$archives[$i]";
  202.             print "<li><a href=$url>$archives[$i]</a>\n";
  203.         }
  204.         print "</ul></td><td valign=top><ul>\n";
  205.         for ($i=$a+$b; $i<=$#archives; $i++) {
  206.             $url = $archive_url . "?$archives[$i]";
  207.             print "<li><a href=$url>$archives[$i]</a>\n";
  208.         }
  209.         print "</ul></td></tr></table>\n";
  210.         print "</blockquote>\n";
  211.         print "<hr><br>\n";
  212.     }
  213.  
  214.     print "</form></body></html>\n";
  215. }
  216.  
  217. sub send_message {
  218.     local ($body, $list, $email);
  219.  
  220.     $body = $_[0] . " " . $_[1];
  221.     $email = $_[2];
  222.  
  223.     $cmd = "echo \"$body\" | /usr/lib/sendmail -f$email majordomo@" . 
  224.         $ENV{'SERVER_NAME'};
  225.     system("$cmd > /dev/null 2>&1");
  226. }
  227.